/*
 ------------------------------------------------------------------------------
 Copyright (C) 2013 Eternal Games.

 This file is part of the GLQuake source code.

 The GLQuake source code is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or (at your
 option) any later version.

 The GLQuake source code is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 more details.

 You should have received a copy of the GNU General Public License along with
 the GLQuake source code; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 ------------------------------------------------------------------------------
*/


//
// game.h - framework used by dynamic-link libraries
//


#ifndef __FRAMEWORK_GAME_H__
#define __FRAMEWORK_GAME_H__


/*
 ==============================================================================

 Game:

 Common definitions between engine and game modules.

 ==============================================================================
*/

#define GAME_FRAMERATE				20
#define GAME_FRAMEMSEC				(1000 / GAME_FRAMERATE)

// Absolute limits
#define MAX_CLIENTS					32
#define MAX_ENTITIES				4096

#define MAX_PLAYER_NAME_LENGTH		64

// Number of packets that must be kept on both client and server for delta
// compression and ping estimation
#define PACKET_BACKUP				32
#define PACKET_MASK					(PACKET_BACKUP - 1)

/*
 ==============================================================================

 USER COMMANDS

 ==============================================================================
*/

// Allow a lot of user command backups for very fast systems
#define	USERCMD_BACKUP				64
#define USERCMD_MASK				(USERCMD_BACKUP - 1)

// if the high bit of the client to server byte is set, the low bits are
// client move cmd bits
// ms and angle2 are allways sent, the others are optional
#define	CM_ANGLE1 	(1<<0)
#define	CM_ANGLE3 	(1<<1)
#define	CM_FORWARD	(1<<2)
#define	CM_SIDE		(1<<3)
#define	CM_UP		(1<<4)
#define	CM_BUTTONS	(1<<5)
#define	CM_IMPULSE	(1<<6)
#define	CM_ANGLE2 	(1<<7)

// the first 16 bits of a packetentities update holds 9 bits
// of entity number and 7 bits of flags
#define	U_ORIGIN1	(1<<9)
#define	U_ORIGIN2	(1<<10)
#define	U_ORIGIN3	(1<<11)
#define	U_ANGLE2	(1<<12)
#define	U_FRAME		(1<<13)
#define	U_REMOVE	(1<<14)		// REMOVE this entity, don't add it
#define	U_MOREBITS	(1<<15)

// if MOREBITS is set, these additional flags are read in next
#define	U_ANGLE1	(1<<0)
#define	U_ANGLE3	(1<<1)
#define	U_MODEL		(1<<2)
#define	U_COLORMAP	(1<<3)
#define	U_SKIN		(1<<4)
#define	U_EFFECTS	(1<<5)
#define	U_SOLID		(1<<6)		// the entity should be solid for prediction

enum userCmdFlags_t {
	UCF_RUNNING						= BIT(0),
	UCF_TALKING						= BIT(1),
	UCF_ANYKEYDOWN					= BIT(2)
};

enum buttonBits_t {
	BUTTON_ATTACK					= BIT(0),
	BUTTON_USE						= BIT(1),
	BUTTON_SPRINT					= BIT(2),
	BUTTON_ZOOM						= BIT(3),
	BUTTON_4						= BIT(4),
	BUTTON_5						= BIT(5),
	BUTTON_6						= BIT(6),
	BUTTON_7						= BIT(7),
	BUTTON_8						= BIT(8),
	BUTTON_9						= BIT(9),
	BUTTON_10						= BIT(10),
	BUTTON_11						= BIT(11),
	BUTTON_12						= BIT(12),
	BUTTON_13						= BIT(13),
	BUTTON_14						= BIT(14),
	BUTTON_15						= BIT(15),
	BUTTON_16						= BIT(16),
	BUTTON_17						= BIT(17),
	BUTTON_18						= BIT(18),
	BUTTON_19						= BIT(19),
	BUTTON_20						= BIT(20),
	BUTTON_21						= BIT(21),
	BUTTON_22						= BIT(22),
	BUTTON_23						= BIT(23),
	BUTTON_24						= BIT(24),
	BUTTON_25						= BIT(25),
	BUTTON_26						= BIT(26),
	BUTTON_27						= BIT(27),
	BUTTON_28						= BIT(28),
	BUTTON_29						= BIT(29),
	BUTTON_30						= BIT(30),
	BUTTON_31						= BIT(31)
};

struct userCmd_t {
	int						time;
	int						flags;
	int						buttons;

	short					forwardMove;
	short					sideMove;
	short					upMove;

	short					angles[3];
};


#endif	// __FRAMEWORK_GAME_H__